﻿/*  Copyright (c) 2012 William Rogers and James Boud

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace JBBRXG11ContentFBXModel
{
    public struct Keyframe
    {
        public int Bone;
        public TimeSpan Time;
        public Matrix Transform;

        public Keyframe(int bone, TimeSpan time, Matrix transform)
        {
            Bone = bone;
            Time = time;
            Transform = transform;
        }
    }

    public class AnimationClip
    {
        public TimeSpan Duration;
        public Keyframe[] Keyframes;  // Combined list of frames for all bones sorted by time

        public AnimationClip(TimeSpan duration, Keyframe[] keyframes)
        {
            Duration = duration;
            Keyframes = keyframes;
        }

        public AnimationClip()
        {
        }
    }

    public class SkinningData
    {
        public Dictionary<string, AnimationClip> AnimationClips;
        public Matrix[] BindPose;
        public Matrix[] InverseBindPose;
        public int[] SkeletonHierarchy;

        public SkinningData(Dictionary<string, AnimationClip> animationClips,
                            Matrix[] bindPose, Matrix[] inverseBindPose,
                            int[] skeletonHierarchy)
        {
            AnimationClips = animationClips;
            BindPose = bindPose;
            InverseBindPose = inverseBindPose;
            SkeletonHierarchy = skeletonHierarchy;
        }

        public SkinningData()
        {
        }
    }

    public struct my_vertex_element
    {
        public VertexElement ve;
    }

    public struct my_mesh_part
    {
        public int vertexOffset, numvertices, primitivecount, startindex;
        public bool computeadjacencyindices, noindices, use32bitindices;
        public ushort[] p16Indices;
        public int[] p32Indices;
        public byte[] pVertices;
        public my_vertex_element[] vertexelements;
        public string[] texturekeys, texturefilenames;
    }

    public struct my_mesh
    {
        public string name;
        public BoundingSphere sphere;
        public my_mesh_part[] parts;
    }

    public class ModelInfoStuff
    {
        public const string versionstring = "V02 ";

        public string stuff;
        public my_mesh[] meshes;
        public SkinningData skinning;

        public ModelInfoStuff(my_mesh[] m, SkinningData sk, string dbtxt)
        {
            meshes = m;
            skinning = sk;
            stuff = versionstring + dbtxt;
        }

        public ModelInfoStuff()
        {
            meshes = null;
            skinning = null;
            stuff = "";
        }
    }
}
